package com.smart.web.controller.system;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.smart.common.core.domain.R;
import com.smart.common.core.page.PageQuery;
import com.smart.system.domain.vo.AttendanceVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;

import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.smart.common.annotation.Log;
import com.smart.common.core.controller.BaseController;
import com.smart.common.enums.BusinessType;
import com.smart.system.domain.AttendanceRecord;
import com.smart.system.service.IAttendanceRecordService;
import com.smart.common.utils.poi.ExcelUtil;
import com.smart.common.core.page.TableDataInfo;

/**
 * 考勤记录Controller
 * 
 * @author smart
 * @date 2024-09-18
 */
@RestController
@RequestMapping("/system/record")
@Api(tags = "考勤管理")
public class AttendanceRecordController extends BaseController
{
    @Autowired
    private IAttendanceRecordService attendanceRecordService;

    /**
     * 查询考勤记录列表
     */
    @ApiOperation(value = "查询考勤记录列表")
    //@PreAuthorize("@ss.hasPermi('system:record:list')")
    @GetMapping("/list")
    public R<IPage<AttendanceRecord>> list(AttendanceRecord attendanceRecord, PageQuery pageQuery)
    {
        IPage<AttendanceRecord> list = attendanceRecordService.selectAttendanceRecordList(attendanceRecord,pageQuery.toPage());
        return R.ok(list);
    }

    /**
     * 修改考勤记录
     */
    @ApiOperation(value = "补卡")
    //@PreAuthorize("@ss.hasPermi('system:record:edit')")
    @Log(title = "补卡", businessType = BusinessType.UPDATE)
    @PostMapping
    @ApiImplicitParams({
            @ApiImplicitParam(name = "userId", value = "用户id", required = true, dataType = "Integer"),
            @ApiImplicitParam(name = "date", value = "日期", required = true, dataType = "Date"),
            @ApiImplicitParam(name = "type", value = "0上班卡1下班卡3全部/不传也是全部", required = false, dataType = "Integer"),
    })
    public R<Integer> edit(Integer userId,Date date,Integer type)
    {
        return R.ok(attendanceRecordService.updateAttendanceRecord(userId,date,type));
    }


    /**
     * 考勤情况
     */
    @ApiOperation(value = "考勤情况")
    //@PreAuthorize("@ss.hasPermi('system:record:query')")
    @Log(title = "考勤情况", businessType = BusinessType.UPDATE)
    @GetMapping("attendance")
    public R<AttendanceVo> attendance(Integer userId, Date startTime, Date endTime)
    {
        return R.ok(attendanceRecordService.attendance(userId,startTime,endTime));
    }
}
